package org.example.item.wallet;

import org.example.models.abstracts.AbstractLiving;
import org.example.models.abstracts.AbstractItem;

import java.util.Objects;

public class Wallet extends AbstractItem {

    private int balance;

    public Wallet(int balance) {
        super("Wallet");
        setBalance(balance);
    }

    public Wallet() {
        this(0);
    }

    public void setBalance(int balance) {
        if (balance < 0) throw new IllegalArgumentException("Wallet balance must be positive or zero. Provided: " + balance);
        this.balance = balance;
    }

    public int getBalance() {
        return balance;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Wallet wallet)) return false;
        return getBalance() == wallet.getBalance();
    }

    @Override
    public int hashCode() {
        return Objects.hash(getBalance());
    }

    @Override
    public String toString() {
        return "Wallet[balance=" + getBalance() + "]";
    }
}
